package com.czl.module_storehouse.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.base.data.bean.tengyun.BorrowBean;
import com.czl.module_storehouse.R;

import java.util.List;

/**
 * @author by xubin,
 * @date on 2022/2/10.
 * PS: Not easy to write code, please indicate.
 */
public class BorrowAdapter extends BaseQuickAdapter<BorrowBean, BaseViewHolder> {

    private boolean visible;

    public BorrowAdapter(int layoutResId, @Nullable List<BorrowBean> data) {
        super(layoutResId, data);
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, BorrowBean item) {
        helper.setText(R.id.tv_title, item.getBorrowName())
                .setText(R.id.tv_date, item.getApplyDate())
                .setText(R.id.tv_code, "借用单：" + (item.getBorrowCode() == null ? "" : item.getBorrowCode()))
                .setText(R.id.tv_department, "借用部门：" + (item.getBorrowPersonDepartment() == null ? "" : item.getBorrowPersonDepartment()))
                .setText(R.id.tv_desc, "借用说明：" + (item.getApplyComment() == null ? "" : item.getApplyComment()))
                .setText(R.id.tv_company, "借用公司：" + (item.getBorrowCompanyName() == null ? "" : item.getBorrowCompanyName()))
                .setText(R.id.tv_return_date, "拟还日期：" + (item.getMoReturnDate() == null ? "" : item.getMoReturnDate()))
                .setVisible(R.id.tv_borrow_total, item.isVisableNum(visible))
                .setText(R.id.tv_borrow_total, item.getBorrowTotalTextNum("已借"));
        helper.getView(R.id.tv_borrow_total).setOnClickListener(v -> {
            if (getOnItemChildClickListener() != null) {
                getOnItemChildClickListener().onItemChildClick(BorrowAdapter.this, v, helper.getAbsoluteAdapterPosition() - getHeaderLayoutCount());
            }
        });
        helper.getView(R.id.cl_root).setOnClickListener(v -> {
            if (getOnItemChildClickListener() != null) {
                getOnItemChildClickListener().onItemChildClick(BorrowAdapter.this, v, helper.getAbsoluteAdapterPosition() - getHeaderLayoutCount());
            }
        });
    }
}

